import { SETNOWLIST, SETSOONLIST } from '../mutation-type'
import http from '@/utils/http'
// import fetch from 'fetch-ie8'

const module = {
  namespaced: true, // 命名空间
  state: {
    nowlist: [],
    soonlist: []
  },
  actions: {
    getCinemasAction (context, payload) {
      function getNowlist () {
        return http(`/gateway?cityId=${context.rootState.cityModule.Postcodes}&pageNum=1&pageSize=10&type=1&k=8317721`, {
          headers: {
            // 'X-Client-Info': '{"a":"3000","ch":"1002","v":"5.0.4","e":"15647165941739461757290","bc":"310100"}',
            'X-Host': 'mall.film-ticket.film.list'
          }
        })
      }
      function getSoonlist () {
        return http(`/gateway?cityId=${context.rootState.cityModule.Postcodes}&pageNum=1&pageSize=10&type=2&k=8317727`, {
          headers: {
            'X-Host': 'mall.film-ticket.film.list'
          }
        })
      }
      Promise.all([getNowlist(), getSoonlist()]).then(res => {
        context.commit('SETNOWLIST', res[0].data.data.films)
        context.commit('SETSOONLIST', res[1].data.data.films)
      })
    }
  },
  mutations: {
    [SETNOWLIST] (state, payload) {
      state.nowlist = payload
    },
    [SETSOONLIST] (state, payload) {
      state.soonlist = payload
    }
  }
}

export default module
